package com.example.demo.struct.proxy.dynamic;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Desc:
 * @Author zzz
 * @Date 2021/2/24
 * @Version V1.0
 */
@Data
@AllArgsConstructor
public class AxiosInvocationHandler<T> implements InvocationHandler {

    T target;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        preRequest();
        Object result = method.invoke(target, args);
        System.out.println(result);
        postRequest();
        return result;
    }


    private void preRequest() {
        System.out.println("before request");
    }

    private void postRequest() {
        System.out.println("after request");
    }

}
